// pages/pkResult/pkResult.js
const app = getApp().globalData;

Page({
  /**
   * 页面的初始数据
   */
  data: {
    avatar: '',
    name: '',
    score: '',
    otherAvatar: '',
    otherName: '',
    otherScore: '',
    finalScore: '',
    matchType: '',
    qCataId: '',
    cataname: '',
    openid: '',
    unitCatory: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      name: wx.getStorageSync('userInfo').nickName,
      avatar: wx.getStorageSync('userInfo').avatarUrl,
      openid: wx.getStorageSync('openid'),
      score: parseInt(options.meScore),
      otherAvatar: options.avatar,
      otherName: options.name,
      otherScore: parseInt(options.otherScore),
      finalScore: options.finalScore,
      matchType: options.matchType,
      qCataId: options.qCataId,
      cataname: options.cataname
    })
    var token = wx.getStorageSync('token')
    var openId = wx.getStorageSync('openid')
    this.questionUnit(openId, token) //单位题库
    //分享给群
    wx.showShareMenu({
      withShareTicket: true
    })
  },

  //单位题库
  questionUnit(openId, token) {
    let parameter = openId + '&token=' + token + '&fid=' + app.fid,
      that = this;
    wx.request({
      url: common.baseUrl + 'data/search/unitQCata?openId=' + parameter,
      method: 'get',
      success: (res) => {
        if (res.data.success) {
          that.setData({
            unitCatory: res.data.data
          })
        }
      }
    })
  },

  /**
   * 用户点击右上角分享，分享按钮  分内部自定义和外部分享
   */
  onShareAppMessage: function (res) {
    let that = this;
    if (res.from === 'button') {
      //来自页面内转发按钮
      console.log(res.target)
    } else {
      console.log('外部转发')
    }
    return {
      title: '快来挑战吧',
      path: '/pages/zstz/share/share?score=' + that.data.score + '&meName=' + that.data.name + '&meAvatar=' + that.data.avatar + '&otherScore=' + that.data.otherScore + '&finalScore=' + that.data.finalScore + '&name=' + that.data.otherName + '&avatar=' + that.data.otherAvatar + '&fid=' + app.fid + '&fidEnc=' + app.fidEnc
    }
  },

  onShareTimeline: function (res) {
    let that = this;
    return {
      title: '快来挑战吧',
      query: 'score=' + that.data.score + '&meName=' + that.data.name + '&meAvatar=' + that.data.avatar + '&otherScore=' + that.data.otherScore + '&finalScore=' + that.data.finalScore + '&name=' + that.data.otherName + '&avatar=' + that.data.otherAvatar + '&fid=' + app.fid + '&fidEnc=' + app.fidEnc
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})